package com.wh.beans.custom;


import com.legend.utils.StringUtils;
import com.wh.model.CustomField;

import java.text.MessageFormat;

public class Select implements ICustomLabel {

	@Override
	public String getCustomLabel(CustomField field, LabelType type) {
		String label = "", template = "";
		String fieldLittleName = StringUtils.getFieldLittleCamel(field.getFieldDbName());
		String fieldBigName = StringUtils.getFieldBigCamel(field.getFieldDbName());
		//List<ValueText> lst = new ArrayList<ValueText>();
		Float width = field.getInputWidth();
		Integer panelHeight = field.getInputHeight();
		String defValue = "";
		StringBuffer s;
		String enumName = field.getDataLinkedEnum();
		if (panelHeight==null) {
			panelHeight=200;
		}
		if (width==null) {
			width=200f;
		}
		switch (type) {
		case add:
			boolean editable = (field.getInputProperty() & 32) == 32;
			s = new StringBuffer();
			defValue = MessageFormat.format("Enum.{0}[0].value", enumName);
			s.append(MessageFormat
					.format("<select id=\"sl{0}\" class=\"easyui-combobox\" data-options=\"editable:{1},valueField:\''value\'',textField:\''text\'',data:Enum.{2},value:{3}\" panelHeight=\"{4}\" name=\"{5}\" panelWidth=\"{6}\">",
							fieldBigName, editable, enumName, defValue, panelHeight, fieldLittleName, width));
			s.append("</select>");
			label = s.toString();
			break;
		case edit:
			editable = (field.getInputProperty() & 32) == 32;
			s = new StringBuffer();
			defValue = MessageFormat.format("$'{'info.data.{0}'}'", fieldLittleName);
			s.append(MessageFormat
					.format("<select id=\"sl{0}\" class=\"easyui-combobox\" data-options=\"editable:{1},valueField:\''value\'',textField:\''text\'',data:Enum.{2},value:''{3}''\" panelHeight=\"{4}\" name=\"{5}\"  panelWidth=\"{6}\">",
							fieldBigName, editable, enumName, defValue, panelHeight, fieldLittleName, width));
			s.append("</select>");

			label = s.toString();
			break;
		case view:
			template = "<script type=\"text/javascript\">document.write(getEnumText(Enum.FormType,$'{'info.data.{0}'}',1));</script>";
			label = MessageFormat.format(template, fieldLittleName);
			break;
		default:
			break;
		}
		return label;
	}

}
